home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / dos6mm.zip / CMOSRSTR.ASM < prev    next >
Assembly Source File  |  1993-03-31  |  11KB  |  252 lines

  1. ;****************************************************************************
  2. ; CMOSRSTR restores the contents of CMOS RAM from a file. Its syntax is:
  3. ;
  4. ;       CMOSRSTR [d:][path]filename
  5. ;
  6. ; where "filename" is the name of the file from which CMOS data will be
  7. ; read. Use CMOSSAVE to save the contents of CMOS RAM to disk.
  8. ;****************************************************************************
  9.  
  10. CMOS_ADDR       equ     70h                     ;CMOS address port
  11. CMOS_DATA       equ     71h                     ;CMOS data port
  12.  
  13. code            segment
  14.                 assume  cs:code,ds:code
  15.                 org     100h
  16. begin:          jmp     main
  17.  
  18. copyright       db      "CMOSRSTR 2.0 Copyright (c) 1993 Jeff Prosise",13,10
  19.                 db      "From: PC Magazine DOS 6 Memory Management "
  20.                 db      "with Utilities",13,10,13,10,"$"
  21.  
  22. helpmsg         db      "Restores the configuration data stored in CMOS RAM "
  23.                 db      "from a file.",13,10,13,10
  24.                 db      "CMOSRSTR [d:][path]filename",13,10,13,10
  25.                 db      "  filename  Name of the file from which "
  26.                 db      "configuration data will be read.",13,10,13,10
  27.                 db      "Use CMOSSAVE to save CMOS configuration data."
  28.                 db      13,10,"$"
  29.  
  30. signature       db      "CMOSSAVE"
  31.  
  32. errmsg1         db      "Syntax: CMOSRSTR [d:][path]filename",13,10,"$"
  33. errmsg2         db      "Invalid path name or file not found",13,10,"$"
  34. errmsg3         db      "Error reading file",13,10,"$"
  35. errmsg4         db      "File does not contain valid CMOS data",13,10,"$"
  36.  
  37. msg             db      " bytes were copied from disk to CMOS RAM",13,10,"$"
  38.  
  39. handle          dw      ?                       ;File handle
  40. cmoslength      dw      ?                       ;Number of bytes to restore
  41.  
  42. ;****************************************************************************
  43. ; Procedure MAIN
  44. ;****************************************************************************
  45.  
  46. main            proc    near
  47.                 cld                             ;Clear direction flag
  48.                 mov     si,81h                  ;Point SI to command line
  49.                 call    scanhelp                ;Scan for "/?" switch
  50.                 jnc     main1                   ;Branch if not found
  51.  
  52.                 mov     ah,09h                  ;Display help text and exit
  53.                 mov     dx,offset helpmsg       ;with ERRORLEVEL=0
  54.                 int     21h
  55.                 mov     ax,4C00h
  56.                 int     21h
  57. ;
  58. ; Parse the command line and read the data file.
  59. ;
  60. main1:          call    findchar                ;Advance to next character
  61.                 jnc     main2                   ;Branch if found
  62.  
  63.                 mov     dx,offset errmsg1       ;Load error message address
  64. error:          mov     ah,09h                  ;Display error message
  65.                 int     21h
  66.                 mov     ax,4C01h                ;Exit with ERRORLEVEL=1
  67.                 int     21h
  68.  
  69. main2:          mov     dx,si                   ;Convert the file name to
  70.                 call    finddelim               ;ASCIIZ format
  71.                 mov     byte ptr [si],0
  72.  
  73.                 mov     ax,3D00h                ;Open the file
  74.                 int     21h
  75.                 mov     dx,offset errmsg2
  76.                 jc      error                   ;Branch if the call failed
  77.                 mov     handle,ax               ;Save the file handle
  78.  
  79.                 mov     bx,ax                   ;Read the data from the file
  80.                 mov     ah,3Fh
  81.                 mov     cx,512
  82.                 mov     dx,offset scanhelp
  83.                 int     21h
  84.                 mov     dx,offset errmsg3
  85.                 jc      error                   ;Branch on error
  86.  
  87.                 mov     cx,ax                   ;Save byte count
  88.                 mov     ah,3Eh                  ;Close the file
  89.                 mov     bx,handle
  90.                 int     21h
  91.  
  92.                 mov     dx,offset errmsg4       ;Error if more than
  93.                 cmp     cx,73                   ;265 or fewer than 73
  94.                 jb      error                   ;bytes were read from
  95.                 cmp     cx,265                  ;the file
  96.                 ja      error
  97.                 sub     cx,9                    ;Compute CMOS length
  98.                 mov     cmoslength,cx           ;Save the result
  99.  
  100.                 mov     cx,8                    ;Error if the file does
  101.                 mov     si,offset scanhelp      ;not contain a CMOSSAVE
  102.                 mov     di,offset signature     ;signature
  103.                 repe    cmpsb
  104.                 jne     error
  105.  
  106.                 xor     al,al                   ;Error if the file does
  107.                 mov     cx,cmoslength           ;not contain a valid
  108.                 add     cx,8                    ;checksum
  109.                 mov     di,offset scanhelp
  110. main2a:         add     al,[di]
  111.                 inc     di
  112.                 loop    main2a
  113.                 cmp     al,[di]
  114.                 jne     error
  115. ;
  116. ; Write the data from the file to CMOS RAM.
  117. ;
  118.                 cld                             ;Clear direction flag
  119.                 xor     cx,cx                   ;Initialize counter
  120.  
  121. main3:          mov     al,cl                   ;Get address in AL
  122.                 cli                             ;Interrupts off
  123.                 out     CMOS_ADDR,al            ;Output CMOS address
  124.                 jmp     short $+2               ;I/O delay
  125.                 jmp     short $+2
  126.                 lodsb                           ;Get a byte of data
  127.                 out     CMOS_DATA,al            ;Write it to CMOS RAM
  128.                 sti                             ;Interrupts on
  129.                 inc     cx                      ;Increment counter
  130.                 cmp     cx,cmoslength           ;Loop if there are more
  131.                 jne     main3                   ;bytes to copy
  132.  
  133.                 mov     al,80h                  ;Make sure NMI is enabled
  134.                 out     CMOS_ADDR,al            ;if this happens to be a
  135.                 jmp     short $+2               ;PS/2
  136.                 jmp     short $+2
  137.                 in      al,CMOS_DATA
  138. ;
  139. ; Display message and exit.
  140. ;
  141.                 mov     ah,09h                  ;Display copyright message
  142.                 mov     dx,offset copyright
  143.                 int     21h
  144.  
  145.                 mov     ax,cmoslength           ;Display the number of
  146.                 call    bin2asc                 ;bytes that were restored
  147.                 mov     ah,09h
  148.                 mov     dx,offset msg
  149.                 int     21h
  150.  
  151.                 mov     ax,4C00h                ;Exit with ERRORLEVEL=0
  152.                 int     21h
  153. main            endp
  154.  
  155. ;****************************************************************************
  156. ; BIN2ASC converts a binary value in AX to ASCII form and displays it.
  157. ;****************************************************************************
  158.  
  159. bin2asc         proc    near
  160.                 mov     bx,10                   ;Initialize divisor word and
  161.                 xor     cx,cx                   ;digit counter
  162. b2a1:           inc     cx                      ;Increment digit count
  163.                 xor     dx,dx                   ;Divide by 10
  164.                 div     bx
  165.                 push    dx                      ;Save remainder on stack
  166.                 or      ax,ax                   ;Loop until quotient is zero
  167.                 jnz     b2a1
  168. b2a2:           pop     dx                      ;Retrieve a digit from stack
  169.                 add     dl,30h                  ;Convert it to ASCII
  170.                 mov     ah,2                    ;Display it
  171.                 int     21h
  172.                 loop    b2a2                    ;Loop until done
  173.                 ret
  174. bin2asc         endp
  175.  
  176. ;****************************************************************************
  177. ; SCANHELP scans the command line for a /? switch. If found, carry returns
  178. ; set and SI contains its offset. If not found, carry returns clear.
  179. ;****************************************************************************
  180.  
  181. scanhelp        proc    near
  182.                 push    si                      ;Save SI
  183. scanloop:       lodsb                           ;Get a character
  184.                 cmp     al,0Dh                  ;Exit if end of line
  185.                 je      scan_exit
  186.                 cmp     al,"?"                  ;Loop if not "?"
  187.                 jne     scanloop
  188.                 cmp     byte ptr [si-2],"/"     ;Loop if not "/"
  189.                 jne     scanloop
  190.  
  191.                 add     sp,2                    ;Clear the stack
  192.                 sub     si,2                    ;Adjust SI
  193.                 stc                             ;Set carry and exit
  194.                 ret
  195.  
  196. scan_exit:      pop     si                      ;Restore SI
  197.                 clc                             ;Clear carry and exit
  198.                 ret
  199. scanhelp        endp
  200.  
  201. ;****************************************************************************
  202. ; FINDCHAR advances SI to the next non-white-space character. On return,
  203. ; carry set indicates EOL was encountered; carry clear indicates it was not.
  204. ;****************************************************************************
  205.  
  206. findchar        proc    near
  207.                 lodsb                           ;Get the next character
  208.                 cmp     al,09h                  ;Loop if tab
  209.                 je      findchar
  210.                 cmp     al,20h                  ;Loop if space
  211.                 je      findchar
  212.                 cmp     al,2Ch                  ;Loop if comma
  213.                 je      findchar
  214.                 dec     si                      ;Point SI to the character
  215.                 cmp     al,0Dh                  ;Exit with carry set if end
  216.                 je      eol                     ;of line is reached
  217.  
  218.                 clc                             ;Clear carry and exit
  219.                 ret
  220.  
  221. eol:            stc                             ;Set carry and exit
  222.                 ret
  223. findchar        endp
  224.  
  225. ;****************************************************************************
  226. ; FINDDELIM advances SI to the next white-space character. On return,
  227. ; carry set indicates EOL was encountered.
  228. ;****************************************************************************
  229.  
  230. finddelim       proc    near
  231.                 lodsb                           ;Get the next character
  232.                 cmp     al,09h                  ;Exit if tab
  233.                 je      fd_exit
  234.                 cmp     al,20h                  ;Exit if space
  235.                 je      fd_exit
  236.                 cmp     al,2Ch                  ;Exit if comma
  237.                 je      fd_exit
  238.                 cmp     al,0Dh                  ;Loop back for more if end
  239.                 jne     finddelim               ;of line isn't reached
  240.  
  241.                 dec     si                      ;Set carry and exit
  242.                 stc
  243.                 ret
  244.  
  245. fd_exit:        dec     si                      ;Clear carry and exit
  246.                 clc
  247.                 ret
  248. finddelim       endp
  249.  
  250. code            ends
  251.                 end     begin
  252.